# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=iputils
pkgver=20240117
pkgrel=0
pkgdesc="IP Configuration Utilities"
url="https://github.com/iputils/iputils/"
arch="all"
license="BSD-3-Clause AND GPL-2.0-or-later"
replaces="bbsuid"
makedepends="
	libcap-dev
	meson
	"
subpackages="
	iputils-arping
	iputils-clockdiff
	iputils-ping
	iputils-tracepath
	"
source="iputils-$pkgver.tar.xz::https://github.com/iputils/iputils/releases/download/$pkgver/iputils-$pkgver.tar.xz"
# checks need suid/setcap'd binaries
# ping is suid
options="suid !check"

build() {
	abuild-meson \
		-Db_lto=true \
		-DNO_SETCAP_OR_SUID=true \
		-DBUILD_MANS=false \
		-DUSE_IDN=false \
		-DUSE_GETTEXT=false \
		. output
	meson compile -C output
}

check() {
	meson test --no-rebuild --print-errorlogs -C output
}

package() {
	depends="
		iputils-arping=$pkgver-r$pkgrel
		iputils-clockdiff=$pkgver-r$pkgrel
		iputils-ping=$pkgver-r$pkgrel
		iputils-tracepath=$pkgver-r$pkgrel
		"

	install -Dm4755 output/ping/ping "$pkgdir"/bin/ping

	for name in arping clockdiff tracepath; do
		install -Dm755 output/$name "$pkgdir"/usr/sbin/$name
	done

	ln -s tracepath "$pkgdir"/usr/sbin/tracepath6
	ln -s ping "$pkgdir"/bin/ping6
}

arping() {
	pkgdesc="$pkgdesc (arping utility)"
	amove usr/sbin/arping
}

clockdiff() {
	pkgdesc="$pkgdesc (clockdiff utility)"
	amove usr/sbin/clockdiff
}

ping() {
	pkgdesc="$pkgdesc (ping utility)"
	amove bin/ping*
}

tracepath() {
	pkgdesc="$pkgdesc (tracepath utility)"
	amove usr/sbin/tracepath*
}

sha512sums="
c45822c5641f194dc07cba919c13a4b7a79d050bb53957a894ebb6ccc1f71bac1f26489e13d18ef1ce235982f5fa1824e677f95037a0f5cce6bcb94be4c2e2de  iputils-20240117.tar.xz
"
